/* -----------------------------------------------------------------------
 * Paul Cohen
 * CS 362, Summer 2014
 * Assignment 3
 *
 * unittest4.c - testing Dominion's gainCard() function
 * 
 * -----------------------------------------------------------------------
 */

#include "unittest4.h"
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>


int unit_test4()
{    
    int seed = 1000;
    int numPlayers = 2;
    int oldDeckCount = 0;
    int oldHandCount = 0;
    int successes = 0;
    
    struct gameState g;
    int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
    
    printf("\nUnit Test 4: testing gainCard()\n------------\n");        
    initializeGame(numPlayers, k, seed, &g);
    
    // test various cases in gainCard() with the estate card
    g.supplyCount[1] = 0;
    if (gainCard(1, &g, 0, 0) == -1)
        successes++;
    else 
		printf("Test failed - card supply count at 0.\n"); 

    g.supplyCount[1] = 4;
    gainCard(1, &g, 0, 0);
    if ((g.discardCount[0] == 1) && (g.discard[0][0] == 1))
        successes++;
    else 
        printf("Test failed - card not discarded properly.\n");
    
    oldDeckCount = g.deckCount[0];
    gainCard(1, &g, 1, 0);
    if ((g.deckCount[0] == oldDeckCount + 1) && (g.deck[0][oldDeckCount] == 1))
        successes++;
    else 
        printf("Test failed - card not added to deck properly.\n");

    oldHandCount = g.handCount[0];
    gainCard(1, &g, 2, 0);
    if ((g.deckCount[0] == oldHandCount + 1) && (g.deck[0][oldHandCount] == 1))
        successes++;
    else 
        printf("Test failed - card not added to deck properly.\n");


    printf("gainCard() tests completed!\n");
    printf("%d out of 4 tests successful.\n", successes);

    return 0;
}
